#ifndef __SPJ_CODE_COMPILE_EVENT_HPP__
#define __SPJ_CODE_COMPILE_EVENT_HPP__


#include "base_event.hpp"

namespace run_code_event_space {

struct spj_code_compile_event : base_event<spj_code_compile_event>  {
    template <class U>
    ProcessStatus execute_impl(run_code_context_t<U>& context);
};

template <class U>
ProcessStatus spj_code_compile_event::execute_impl(run_code_context_t<U>& context) {
    ProcessStatus ps;
    const RuncodeParams& params = context.params;
    const U& judge_type = context.judge_type;
    auto& [spjLang, spjCodeFile, spjBinFile, spjCompileStr, spjRunStr] = judge_type.spjCodeInfo;
    Log::instance().getOutput() << "spjCodeInfo:" << endl << judge_type.spjCodeInfo;
    ps = general_execution_strategy::_copy<false>(judge_type.spjFile, spjCodeFile, spjLang);
    if (ps.result != RUN_OK) {
        ps.result = SYS_ERROR;
        return ps;
    }
    ps = general_execution_strategy::_compile<false>(spjCodeFile, spjBinFile, spjCompileStr);
    if (ps.result != RUN_OK) {
        ps.result = SPJFILE_COMPILE_ERROR;
        return ps;
    }
    judge_type.spjCompileOk = true;
    return ps;
}

}

#endif /* __SPJ_CODE_COMPILE_EVENT_HPP__ */
